<template>
  <el-dialog append-to-body title="案件中止" width="640px" top="5vh" :visible="visible" @close="handleClose">
    <el-form :model="form" :rules="rules" ref="form" class="white-card" label-width="160px">
      <el-form-item label="中止原因：" prop="reason">
        <el-select v-model="form.reason" placeholder="请选择" style="width: 100%" @change="onSelectChange">
          <el-option v-for="item in optionList" :key="item.id" :label="item.name" :value="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="中止备注：" prop="comment">
        <el-input v-model="form.comment" show-word-limit maxlength="300" placeholder="请输入详细描述" type="textarea" :autosize="{ minRows: 6 }"></el-input>
      </el-form-item>

      <el-form-item label="中止调查告知单：" prop="attachmentFile">
        <upload-input :file-list="form.attachmentFile" :tipsText="''"></upload-input>
      </el-form-item>
    </el-form>

    <div class="split"></div>
    <div class="dialog-footer-btn">
      <el-button @click="handleClose" type="primary" plain>关闭</el-button>
      <el-button @click="handleSubmit" :loading="submitting" type="primary">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import * as workOrderApi from "@/api/workOrder/index";
import * as mixins from "@/utils/mixins";
import * as dictApi from "@/api/dict";
import * as templateApi from "@/api/template";
import { extensionName, filename } from "@/utils/filters";
import uploadInput from "@/components/uploadInput/uploadInput.vue";

export default {
  components: { uploadInput },
  name: "suspendDialog",
  mixins: [mixins.loading, mixins.form, mixins.dialog],
  filters: { extensionName, filename },
  props: ["visible", "workOrderNo", "type"],
  data() {
    return {
      submitting: false,
      form: {
        reason: "",
        comment: "",
        attachmentFile: [],
        isDoudi: false,
      },
      rules: {
        reason: [{ required: true, message: "请选择" }],
        comment: [{ required: true, message: "请填写" }],
        attachmentFile: [{ required: true, message: "请上传" }],
      },
      optionList: [],
    };
  },
  methods: {
    show() {
      dictApi.list({ parentCode: "1003" }).then((res) => {
        this.optionList = res.result;
      });

      templateApi.detailByCode(1007).then((res) => {
        this.form.comment = res.result.value;
      });

      // this.$nextTick(() => {
      //   this.bindFileChangeEvent('attachmentFile', 1)
      // })
    },
    handleSubmit() {
      this.validateAndConfirm("form", "确定要中止该案件么？")
        .then(() => {
          this.submitting = true;
          return workOrderApi[this.type].stop({
            ...this.form,
            attachmentFile: this.form.attachmentFile,
            workOrderNo: this.workOrderNo,
          });
        })
        .then(() => {
          this.$emit("success");
          this.handleClose();
        })
        .finally(() => (this.submitting = false));
    },
    onSelectChange(e) {
      const doudi = this.optionList.find((item) => item.name === e).value;
      this.form.isDoudi = doudi === "1" ? true : false;
    },
  },
};
</script>

<style lang="less" scoped>
.tips {
  text-align: center;
  margin-bottom: 20px;
}
</style>
